package main

import (
	_ "TrainApp/routers"
	"TrainApp/tasks"

	"fmt"

	"github.com/astaxie/beego"
	"github.com/astaxie/beego/orm"
	_ "github.com/go-sql-driver/mysql"
)

func init() {
	// set default database
	userName := beego.AppConfig.String("mysqluser")
	password := beego.AppConfig.String("mysqlpass")
	host := beego.AppConfig.String("mysqlurls")
	db := beego.AppConfig.String("mysqldb")
	charset := beego.AppConfig.String("mysqlcharset")

	mysqlParam := "charset=" + charset

	url := fmt.Sprintf("%s:%s@tcp(%s)/%s?%s", userName, password, host, db, mysqlParam)

	orm.RegisterDataBase("default", "mysql", url, 30)
}

func main() {
	/*******定时任务*******/
	if beego.AppConfig.String("device_haertbeat_check_enable") == "true" {
		DeviceHeartBeatCheckTask := new(tasks.DeviceHeartBeatCheckTask)
		go DeviceHeartBeatCheckTask.InitTask()
	}
	/*******定时任务*******/

	beego.BConfig.WebConfig.StaticDir["/"] = "www"

	if beego.BConfig.RunMode == "dev" {
		beego.BConfig.WebConfig.DirectoryIndex = true
		beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
	}

	beego.Run()
}
